Factory Girl Magic and confusion

jamesperet 9 anni fa
parent
commit
be4c4da183
8 ha cambiato i file con 54 aggiunte e 16 eliminazioni
  1. 0 1
      Gemfile
  2. 0 5
      Gemfile.lock
  3. 1 1
      config/locales/en.yml
  4. 14 1
      features/blog.feature
  5. 24 1
      features/step_definitions/blog_steps.rb
  6. 1 0
      features/support/env.rb
  7. 1 1
      features/support/paths.rb
  8. 13 6
      spec/factories.rb

+ 0 - 1
Gemfile

@@ -57,7 +57,6 @@ gem 'rails_12factor', group: :production
57 57
 group :test do
58 58
   gem "rspec"
59 59
   gem "rspec-rails"
60
-  gem "webrat"
61 60
   gem 'cucumber-rails', :require => false
62 61
   gem 'database_cleaner'
63 62
   gem "factory_girl_rails", "~> 4.0", :require => false

+ 0 - 5
Gemfile.lock

@@ -248,10 +248,6 @@ GEM
248 248
       json (>= 1.8.0)
249 249
     warden (1.2.3)
250 250
       rack (>= 1.0)
251
-    webrat (0.7.3)
252
-      nokogiri (>= 1.2.0)
253
-      rack (>= 1.0)
254
-      rack-test (>= 0.5.3)
255 251
     xpath (2.0.0)
256 252
       nokogiri (~> 1.3)
257 253
 
@@ -296,4 +292,3 @@ DEPENDENCIES
296 292
   turbolinks
297 293
   twitter-bootstrap-rails
298 294
   uglifier (>= 1.3.0)
299
-  webrat

+ 1 - 1
config/locales/en.yml

@@ -206,7 +206,7 @@ en:
206 206
     dashboard: Dashboard
207 207
     files: Files
208 208
     users: Users
209
-    posts: posts
209
+    posts: Posts
210 210
     new_blog_post: New Post
211 211
     upload_file: Upload File
212 212
     welcome: Welcome back

+ 14 - 1
features/blog.feature

@@ -21,4 +21,17 @@ Feature: Manage Articles
21 21
 		When I go to the blog page 
22 22
 		And I click in the link "Hello World" 
23 23
 		Then I should see "Hello World" 
24
-		And I should see "Welcome to the website"
24
+		And I should see "Welcome to the website"
25
+
26
+	Scenario: Post Article
27
+		Given I am logged in as admin
28
+		Then I click in the link "Admin Panel"
29
+		And I click in the link "Posts"
30
+		And I click in the link "New Post"
31
+		Then I fill in "Title" with "Test 002"
32
+		And I fill in "Slug" with "test_002"
33
+		And I fill in "Description" with "Another blog post test"
34
+		And I fill in "post_content" with "This is blog post test number 002!"
35
+		And I click in the button "Save"
36
+		Then I should see "Test 002"
37
+		And I should see "This is blog post test number 002!"

+ 24 - 1
features/step_definitions/blog_steps.rb

@@ -1,8 +1,13 @@
1
+include Warden::Test::Helpers
2
+
1 3
 Info.create( :website_name => 'Website', :tagline => 'A Ruby on Rails app template', :default_language => 'en' )
2 4
 
3 5
 Given /^the following (.+) list ?$/ do |factory, table| 
6
+  user = FactoryGirl.create(:user) 
4 7
   table.hashes.each do |hash| 
5
-    FactoryGirl.create(factory, hash) 
8
+    post = FactoryGirl.create(factory, hash)
9
+    post.author = user
10
+    post.save
6 11
   end
7 12
 end
8 13
   
@@ -28,3 +33,21 @@ end
28 33
 When(/^I click in the link "(.*?)"$/) do |arg1|
29 34
   click_link arg1
30 35
 end
36
+
37
+When(/^I click in the button "(.*?)"$/) do |arg1|
38
+  click_button arg1
39
+end
40
+
41
+Given(/^I am logged in as admin$/) do
42
+  user = FactoryGirl.create(:admin)  
43
+  visit new_user_session_path  
44
+  fill_in "Email", :with => 'admin@website.com' 
45
+  fill_in "Password", :with => '12345678' 
46
+  click_button "Submit"
47
+  login_as user, scope: :user
48
+  visit root_path
49
+end
50
+
51
+Then(/^I fill in "(.*?)" with "(.*?)"$/) do |arg1, arg2|
52
+  fill_in arg1, :with => arg2
53
+end

+ 1 - 0
features/support/env.rb

@@ -58,3 +58,4 @@ Cucumber::Rails::Database.javascript_strategy = :truncation
58 58
 require "#{Rails.root}/spec/factories.rb"
59 59
 
60 60
 
61
+

+ 1 - 1
features/support/paths.rb

@@ -9,7 +9,7 @@ module NavigationHelpers
9 9
   
10 10
     when/the blog page/ 
11 11
       visit blog_path 
12
-    
12
+      
13 13
     else
14 14
       raise "Can't find mapping from \"#{page_name}\" to a path."
15 15
     end

+ 13 - 6
spec/factories.rb

@@ -2,11 +2,19 @@ require 'factory_girl'
2 2
 
3 3
 FactoryGirl.define do 
4 4
   
5
-  factory :user, aliases: [:author, :owner] do
6
-    first_name    "John"
7
-    last_name     "Doe"
8
-    email         "johndoe@website.com"
9
-    password      "12345678"    
5
+  factory :user, aliases: [:author] do |f|
6
+    f.first_name "John"
7
+    f.last_name  "Doe"
8
+    f.email      "johndoe@website.com"
9
+    f.password   "12345678"
10
+    f.admin      false
11
+  end
12
+  
13
+  factory :admin, class: User do 
14
+    first_name "admin" 
15
+    email      "admin@website.com"
16
+    password   "12345678"
17
+    admin      true
10 18
   end
11 19
   
12 20
   factory :blog_post do |f|
@@ -15,7 +23,6 @@ FactoryGirl.define do
15 23
     f.content "foobar"  
16 24
     f.published true
17 25
     f.description "foobar is cool" 
18
-    association :author, factory: :user, last_name: "Doe", strategy: :build
19 26
   end 
20 27
   
21 28
 end